package com.winteam.View;


import com.winteam.Bean.RoomType;
import com.winteam.Controler.Updata;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class UNalterRoomType extends JFrame  {
	private JTextField textField_1_fjid;
	private JTextField textField_2_fjlx;
	private JTextField textField_3_fjdj;
	private JTextField textField_4_fjhs;
	private JTextField textField_5_fjbed;
	
	Updata up=new Updata();
	String roomtypes;                                                   
	private JTextField textField;
	public UNalterRoomType(RoomType roomType) {
		super.setTitle("修改房间类型参数");
		this.setBounds(0, 0, 500, 492);
		this.setLocationRelativeTo(null);
 	    this.setResizable(true);
		getContentPane().setLayout(null);
		
		JLabel label = new JLabel("当前的房间类型:");
		label.setBounds(14, 13, 128, 18);
		getContentPane().add(label);


		JLabel label_2 = new JLabel("房间编号 :");
		label_2.setBounds(79, 55, 97, 18);
		getContentPane().add(label_2);
		
		JLabel label_3 = new JLabel("房间类型 :");
		label_3.setBounds(79, 99, 97, 18);
		getContentPane().add(label_3);
		
		JLabel label_4 = new JLabel("预设单价 :");
		label_4.setBounds(79, 136, 97, 18);
		getContentPane().add(label_4);
		
		JLabel label_5 = new JLabel("小时价格 :");
		label_5.setBounds(79, 167, 97, 18);
		getContentPane().add(label_5);

		JLabel label_6 = new JLabel("床位数量 :");
		label_6.setBounds(79, 204, 97, 18);
		getContentPane().add(label_6);

//
		textField_1_fjid = new JTextField();
		textField_1_fjid.setBounds(167, 55, 191, 24);
		getContentPane().add(textField_1_fjid);
		textField_1_fjid.setColumns(10);
		
		textField_2_fjlx = new JTextField();
		textField_2_fjlx.setBounds(167, 99, 191, 24);
		getContentPane().add(textField_2_fjlx);
		textField_2_fjlx.setColumns(10);
		
		textField_3_fjdj = new JTextField();
		textField_3_fjdj.setBounds(167, 136, 191, 24);
		getContentPane().add(textField_3_fjdj);
		textField_3_fjdj.setColumns(10);
		
		textField_4_fjhs = new JTextField();
		textField_4_fjhs.setBounds(167, 167, 191, 24);
		getContentPane().add(textField_4_fjhs);
		textField_4_fjhs.setColumns(10);
		
		textField_5_fjbed = new JTextField();
		textField_5_fjbed.setBounds(167, 204, 191, 24);
		getContentPane().add(textField_5_fjbed);
		textField_5_fjbed.setColumns(10);

		textField_1_fjid.setText(roomType.getId()+"");
		roomtypes = roomType.getRoom_type();
		textField_2_fjlx.setText(String.valueOf(roomType.getRoom_type()));
		textField_3_fjdj.setText(String.valueOf(roomType.getR_price()));
		textField_4_fjhs.setText(String.valueOf(roomType.getR_price()));
		textField_5_fjbed.setText(String.valueOf(roomType.getR_bed()));
		
		JButton button = new JButton("保存");
		button.setIcon(new ImageIcon(this.getClass().getResource("img/save.gif")));
		button.setBounds(79, 336, 113, 27);
		getContentPane().add(button);
		JLabel tile = new JLabel(roomtypes);
		tile.setBounds(120, 13, 128, 18);
		getContentPane().add(tile);
		button.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {				
				if(roomType==null){
					return;
				}
				 roomType.setRoom_type(textField_2_fjlx.getText());
				roomType.setR_price(Integer.parseInt(textField_3_fjdj.getText()));
				roomType.setR_hprice(Integer.parseInt(textField_4_fjhs.getText()));
				roomType.setR_bed(Integer.parseInt(textField_5_fjbed.getText()));
				roomType.setId(Integer.parseInt(textField_1_fjid.getText()));

				if (up.updateRoomType(roomType)){
					JOptionPane.showMessageDialog(null,"修改成功");
					dispose();
				}else {
					JOptionPane.showMessageDialog(null,"修改失败");

				}


			}
		});
		
		
		JButton button_1 = new JButton("取消");
		button_1.setIcon(new ImageIcon(this.getClass().getResource("img/cancel.gif")));
		button_1.setBounds(281, 336, 113, 27);
		getContentPane().add(button_1);button_1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
			
	}


}
